package lero.service.impl;

import lero.mapper.RoleMapper;
import lero.pojo.Admin;
import lero.pojo.Role;
import lero.service.RoleServiceI;
import lero.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Roleistrator on 2018/7/16.
 */
@Service
@Transactional
public class RoleServiceImpl implements RoleServiceI {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public void insert(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public List<Role> select(RoleVo vo) {
        return roleMapper.select(vo);
    }

    @Override
    public Role selectOne(int id) {
        return roleMapper.selectOne(id);
    }

    @Override
    public void delete(int id) {
        roleMapper.delete(id);
    }

    @Override
    public void deleteMany(int[] ids) {
        roleMapper.deleteMany(ids);
    }

    @Override
    public void update(Role role) {
        roleMapper.update(role);
    }

    @Override
    public List<Admin> selectAdminNotInCurrentRole(int id) {
        return roleMapper.selectAdminNotInCurrentRole(id);
    }

    @Override
    public List<Admin> selectAdminInCurrentRole(int id) {
        return roleMapper.selectAdminInCurrentRole(id);
    }

    @Override
    public List<Map> selectAllAdmin() {
        return roleMapper.selectAllAdmin();
    }

    @Override
    public void saveAdminIntoCurrentRole(int[] ids, int id) {
        //重新建立角色与用户关系前，需要删除当前角色下的用户
        roleMapper.deleteAdminByCurrentRole(id);
        roleMapper.saveAdminIntoCurrentRole(ids,id);
    }

    @Override
    public void deleteAdminByCurrentRole(int roleId) {
        roleMapper.deleteAdminByCurrentRole(roleId);
    }
}
